<?php

class ActividadController extends GxController {

	public function filters() {
		return array(
				'accessControl',
		);
	}
	
	public function accessRules() {
		return array(
				array('allow',
						'users'=>array('@'),
				),
				array('deny',
						'users'=>array('?'),
				),
		);
	}
	public function actionView($id) {
		$model=$this->loadModel($id, 'Actividad');
		
		$attr = Yii::app()->request->getParam('ActividadSocio');
		$otromodel = new ActividadSocio('search');
		$otromodel->unsetAttributes();
		$otromodel->setAttributes($attr);
		$otromodel->ActividadId=$model->ActividadId;
		$newDataProvider=$otromodel->search();
		$myDataProvider=ActividadSocio::model()->search();
		$myDataProvider->criteria->mergeWith($newDataProvider->criteria);
		$myDataProvider->pagination=array('pageSize'=>12);
		
		$this->render('view', array(
			'model' => $model,
			'myDataProvider'=>  $myDataProvider,
			'otromodel'=>  $otromodel,
		));
	}

	public function actionCreate() {
		$model = new Actividad;


		if (isset($_POST['Actividad'])) {
			$model->setAttributes($_POST['Actividad']);

			if ($model->save()) {
				if (Yii::app()->getRequest()->getIsAjaxRequest())
					Yii::app()->end();
				else
					$this->redirect(array('view', 'id' => $model->ActividadId));
			}
		}

		$this->render('create', array( 'model' => $model));
	}

	public function actionUpdate($id) {
		$model = $this->loadModel($id, 'Actividad');


		if (isset($_POST['Actividad'])) {
			$model->setAttributes($_POST['Actividad']);

			if ($model->save()) {
				$this->redirect(array('view', 'id' => $model->ActividadId));
			}
		}

		$this->render('update', array(
				'model' => $model,
				));
	}

	public function actionDelete($id) {
		if (Yii::app()->getRequest()->getIsPostRequest()) {
			$this->loadModel($id, 'Actividad')->delete();

			if (!Yii::app()->getRequest()->getIsAjaxRequest())
				$this->redirect(array('admin'));
		} else
			throw new CHttpException(400, Yii::t('app', 'Your request is invalid.'));
	}

	public function actionIndex() {
		$dataProvider = new CActiveDataProvider('Actividad');
		$this->render('index', array(
			'dataProvider' => $dataProvider,
		));
	}

	public function actionAdmin() {
		$model = new Actividad('search');
		$model->unsetAttributes();

		if (isset($_GET['Actividad']))
			$model->setAttributes($_GET['Actividad']);

		$this->render('admin', array(
			'model' => $model,
		));
	}

}